package com.kyxx.mycommonproject;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.kyxx.mycommonproject.MaterialDesign.CoordinatorLayout.CoordinatorActivity;
import com.kyxx.mycommonproject.cainixihua.CaiNiXiHuanActivity;
import com.kyxx.mycommonproject.dianpu.ShopActivity;
import com.kyxx.mycommonproject.dialog.DialogActivity;
import com.kyxx.mycommonproject.dingdanxiangqing.OrderDetailActivity;
import com.kyxx.mycommonproject.gouwuche.CartFragment;
import com.kyxx.mycommonproject.gouwuche.CartFragmentActivity;
import com.kyxx.mycommonproject.lunbotu.CarouselFigureActivity;
import com.kyxx.mycommonproject.shangpinfenlei.GoodClassActivity;
import com.kyxx.mycommonproject.shangpinshoucang.FavActivity;
import com.kyxx.mycommonproject.shangpinxiangqing.GoodDetailActivity;
import com.kyxx.mycommonproject.shanping.SplashActivity;
import com.kyxx.mycommonproject.sousuo.SearchActivity;
import com.kyxx.mycommonproject.tongyongAdapter.CommonAdapter;
import com.kyxx.mycommonproject.tongyongAdapter.ViewHolder;
import com.kyxx.mycommonproject.wodedingdan.MyOrderActivity;
import com.kyxx.mycommonproject.wuliugenzong.DeliverTrackActivity;
import com.kyxx.mycommonproject.xianshimiaosha.MiaoShaActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {
    @Bind(R.id.listView)
    ListView listView;
    private List<MainItemBean> lis = new ArrayList<MainItemBean>();
    private String[] title = {
            "轮播图",
            "闪屏",
            "订单详情",
            "商品分类",
            "商品详情",
            "搜索",
            "我的订单",
            "物流跟踪",
            "购物车",
            "提示框",
            "店铺",
            "CoordinataorLayout",
            "我的收藏",
            "限时秒杀&限时特卖",
            "看了又看&猜你喜欢&推荐"
    };
    Object[] cls = {
            CarouselFigureActivity.class,
            SplashActivity.class,
            OrderDetailActivity.class,
            GoodClassActivity.class,
            GoodDetailActivity.class,
            SearchActivity.class,
            MyOrderActivity.class,
            DeliverTrackActivity.class,
            CartFragmentActivity.class,
            DialogActivity.class,
            ShopActivity.class,
            CoordinatorActivity.class,
            FavActivity.class,
            MiaoShaActivity.class,
            CaiNiXiHuanActivity.class
    };
    private Context ctx;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ctx = MainActivity.this;
        ButterKnife.bind(this);
        initData();
        listView.setAdapter(new CommonAdapter<MainItemBean>(ctx, R.layout.item_main, lis) {
            @Override
            protected void convert(ViewHolder viewHolder, final MainItemBean item, int position) {
                viewHolder.setText(R.id.tv_title, item.getTitle());
                viewHolder.setOnClickListener(R.id.tv_title, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        startActivity(new Intent(MainActivity.this, (Class<?>) item.getCls()));
                    }
                });
            }
        });
    }

    private void initData() {
        for (int i = 0; i < title.length; i++) {
            MainItemBean bean = new MainItemBean();
            bean.setTitle(title[i]);
            bean.setCls(cls[i]);
            lis.add(bean);
        }
    }
}
